package main

import (
	"fmt"
	"net/http"

	"runtime"

	"github.com/gin-gonic/gin"
)

func main() {
	// 1.创建路由
	r := gin.Default()
	// 2.绑定路由规则，执行的函数
	// gin.Context，封装了request和response
	r.GET("/", func(c *gin.Context) {
		// body, _ := ioutil.ReadAll(c.Request.Body)
		// fmt.Println("---body------" + string(body))

		fmt.Println("----header-----")
		for k, v := range c.Request.Header {
			// fmt.Println(k, v)
			c.Header(k, v[0])
		}
		// fmt.Println(runtime.Version())
		c.Header("Version", runtime.Version())
		// fmt.Println(c.RemoteIP())
		IP, _ := c.RemoteIP()
		fmt.Println(IP.String())
		fmt.Println(http.StatusOK)
		c.String(http.StatusOK, "hello World!")
	})

	r.GET("/healthz", func(c *gin.Context) {
		c.String(http.StatusOK, "200")
	})
	// 3.监听端口，默认在8080
	// Run("里面不指定端口号默认为8080")
	r.Run()

}
